package net.oschina.archx.spring.web;

import net.oschina.archx.spring.entity.User;
import net.oschina.archx.spring.utils.MessageUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * IndexController
 *
 * @author Archx
 * @date 2015/6/23 0023
 */
@Controller
public class IndexController {

    @RequestMapping("/")
    public String index(@RequestParam(value = "name", required = false) String name, Model model) {
        if (name != null) {
            model.addAttribute("message", MessageUtils.message("hello.message", name));
        }
        return "index";
    }

    @RequestMapping("/json")
    @ResponseBody
    public List<User> json(@RequestBody List<User> users){
        System.out.println(users.size());
        return users;
    }
}
